package com.zysc.processflow.common.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * --日期转换工具--
 * auth: YH
 * date: 2021.12.03
 * */
public class CalendarUtil {

    // 1.获取过去一天的日期时间戳
    public static Long  LastDay(){
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, - 1);
        Date d = c.getTime();
        long ts = d.getTime();
        return ts;
    }

    // 2.获取过去一天的日期(指定日期格式)
    public static String  LastDay(String dateformat){
        SimpleDateFormat format = new SimpleDateFormat(dateformat);
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, - 1);
        Date d = c.getTime();
        String day = format.format(d);
        return day;
    }


    // 3.获取过去一个小时的日期(时间戳)
    public static Long  LastHour(){
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.HOUR, - 1);
        Long time = c.getTimeInMillis();
        return time;
    }
    // 3.获取过去一个小时的日期(指定日期格式)
    public static String  LastHour(String dateformat){
        SimpleDateFormat format = new SimpleDateFormat(dateformat);
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.HOUR, - 1);
        Date d = c.getTime();
        String day = format.format(d);
        return day;
    }


//---------------------------------------------------------------------------------------------
    // 1.获取过去七天的日期,格式化格式
    public static String  LastWeek(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, - 7);
        Date d = c.getTime();
        String day = format.format(d);
        return day;
    }

    // 1.获取过去七天的时间，时间戳格式
    public static String  LastWeekStamp(){
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, - 7);
        long ts = c.getTimeInMillis();
        String res = String.valueOf(ts);
        return res;
    }

    // 2.获取过去一月的日期
    public static String  LastMonth(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.MONTH, -1);
        Date m = c.getTime();
        String mon = format.format(m);
        return mon;
    }

    // 3.获取过去三个月的日期
    public static String  Last3Month(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, -3);
        c.setTime(new Date());
        Date m3 = c.getTime();
        String mon3 = format.format(m3);
        return mon3;
    }

    // 3.获取过去一年的日期
    public static String  LastYear(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.YEAR, -1);
        Date y = c.getTime();
        String year = format.format(y);
        return year;
    }


    // 4.获取过去1分钟的日期
    public static Long  LastMI10(){
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.MINUTE, - 10);
        Date d = c.getTime();
        long ts = d.getTime();
        return ts;
    }
}
